package com.qsdm.es.dao;

import javax.persistence.EntityManager;

import org.apache.log4j.Logger;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.support.JpaDaoSupport;

public class BasicJpaController extends JpaDaoSupport {
	 
	
	Logger logger4J=Logger.getLogger(this.getClass());
	
	public EntityManager getEntityManager() {	       
		
		  EntityManager em = null;
	        em = EntityManagerFactoryUtils.getTransactionalEntityManager(getJpaTemplate().getEntityManagerFactory());
	                
	    	if(em==null){
	    		return getJpaTemplate().getEntityManagerFactory().createEntityManager();
	    	}else {
	    		logger4J.info("Devolviendo un transacional BasicJpaController Returning em:"+em);
	    	}
	    	
			return em;
	    }
	 
}
